/*
** handle_invent_mnt.c for zappy in /home/Smaxo/Travail/zappy-2015-2014s-renard_g/serv-src
**
** Made by maximilien addari
** Login   <addari_m@epitech.net>
**
** Started on  Sun Jul 15 20:03:28 2012 maximilien addari
** Last update Thu Jul 19 17:43:55 2012 pierrick druart
*/

#include	"server.h"

static void	send_data(t_client *client, t_client *perso)
{
  client->send->concat(client->send, "pin ");
  client->send->concat_value(client->send, perso->sock);
  client->send->concat(client->send, " ");
  client->send->concat_value(client->send, perso->gamer->coord.x);
  client->send->concat(client->send, " ");
  client->send->concat_value(client->send, perso->gamer->coord.y);
  client->send->concat(client->send, " ");
  client->send->concat_value(client->send, perso->gamer->inventory[FOOD]);
  client->send->concat(client->send, " ");
  client->send->concat_value(client->send, perso->gamer->inventory[LINEMATE]);
  client->send->concat(client->send, " ");
  client->send->concat_value(client->send, perso->gamer->inventory[DERAUMERE]);
  client->send->concat(client->send, " ");
  client->send->concat_value(client->send, perso->gamer->inventory[SIBUR]);
  client->send->concat(client->send, " ");
  client->send->concat_value(client->send, perso->gamer->inventory[MENDIANE]);
  client->send->concat(client->send, " ");
  client->send->concat_value(client->send, perso->gamer->inventory[PHIRAS]);
  client->send->concat(client->send, " ");
  client->send->concat_value(client->send, perso->gamer->inventory[THYSTAME]);
  client->send->concat(client->send, "\n");
}

static void	send_player(t_list *list, t_client *graph, \
			    t_game *game, t_event *event)
{
  t_client	*client;
  t_item	*tmp;

  (void)game;
  tmp = list->head;
  while (tmp != NULL)
    {
      client = (struct s_client *)tmp->content;
      if (client->gamer != NULL && client->sock == *(int *)event->data)
	send_data(graph, client);
      tmp = tmp->next;
    }
}

char		handle_invent_mnt(t_game *game, t_list *list, t_event *event)
{
  if (game->sleep == 0 || game->sleep > 10000)
  {
    if (game->graphic != NULL)
      send_player(list, game->graphic, game, event);
    return (0);
  }
  return (1);
}
